package br.com.tcf.coverters;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.tcf.dao.AcrescimoDao;
import br.com.tcf.entidades.Acrescimo;

@FacesConverter("acrescimoConverter")  
public class AcrescimoConverter implements Converter{
	public List<Acrescimo> acs;  
	AcrescimoDao dao = new AcrescimoDao();  

	public AcrescimoConverter(){  
		acs = dao.listarAcrescimos();
	}  

	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
		if (value != null && !value.isEmpty()) {
			return (Acrescimo) uiComponent.getAttributes().get(value);
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
		if (value instanceof Acrescimo) {
			Acrescimo entity= (Acrescimo) value;
			if (entity != null && entity instanceof Acrescimo && entity.getId_acrescimo() != null) {

				uiComponent.getAttributes().put(entity.getId_acrescimo().toString(), entity);
				return entity.getId_acrescimo().toString();
			}
		}
		return "";
	}
}